import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const useSessionsStore = defineStore('sessions', () => {
    const sessions = ref([])
    const setSessions = (newSessions) => {
        if (!newSessions) return
        sessions.value = newSessions // 深拷贝
    }
    const createSession = (newSession) => {
        if (!newSession) return
        sessions.value.unshift(newSession) // 深拷贝
    }
    const deleteSession = (sessionId) => {
        if (!sessionId) return
        sessions.value = sessions.value.filter((session) => session.id !== sessionId)
    }
    return { sessions, setSessions, createSession, deleteSession }
}, {
    persist: true
})